Skip to content

Browse and restore Trash in the TUI - #672

Open
WhiskeyTuesday wants to merge 4 commits into
basecamp:mainfrom
WhiskeyTuesday:tui-trash
Open

WhiskeyTuesday wants to merge 4 commits into
basecamp:mainfrom
WhiskeyTuesday:tui-trash

Conversation

@WhiskeyTuesday

@WhiskeyTuesday WhiskeyTuesday commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

The TUI can send mail to Trash but cannot browse it or restore a thread. Add a 0 Trash tab, with paginated browsing, thread reading, and i to restore through HEY's normal topic restore operation.

Trash returns topics rather than posting IDs. The adapter preserves that distinction, blocks posting mutations in Trash, and avoids marking a trashed topic as a seen posting. A restored row leaves the list only after success. Earlier page and live reads cannot bring it back, including after switching sources, and late restore responses cannot remove an unrelated row from another source.

Uses released HEY SDK v0.37.0 for Trash pagination and total counts. The temporary SDK fork replacement has been removed.

make check passes. Tests cover navigation, opaque pagination, total counts, empty pages, opening without a posting observation, restore success and failure, blocked mutations, stale reads, and topic/posting ID collisions.


Summary by cubic

Adds a Trash tab (shortcut 0) to the TUI so trashed threads can be browsed, read, and restored with i. Previously Trash was write-only: mail could be sent there, but there was no way to browse or restore it.

Trash serves topics rather than posting IDs. The adapter keeps that distinction — posting mutations are blocked in Trash, and a trashed topic is never observed as a seen posting. A successful restore removes the row, closes any open reader, and invalidates any read begun earlier, so a stale page or live response cannot resurrect the restored row even after the reader switches sources and back. A failed restore leaves the thread in place to retry and keeps any in-flight refresh valid. Trash is excluded as a move destination. Tests cover navigation, opaque pagination, restore success and failure, blocked mutations, stale reads, and topic/posting ID collisions.

Dependencies

  • Uses Topics.GetTrashPage from the released HEY SDK; the temporary go.mod replace to the fork commit has been removed.

Written for commit f429577. Summary will update on new commits.

View guided diff

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A pending Trash refresh can reinsert a restored topic after navigation because an early return skips request invalidation; the ordering needs a fix and regression test.

1 open issue
What changed in this PR

Adds Trash browsing and restoration to the TUI’s existing mail navigation, while keeping Trash topic IDs separate from posting IDs.

Changes:

  • Adds a 0 Trash tab with pagination, thread reading, and i to restore.
  • Blocks posting mutations in Trash and adds tests for restore outcomes, stale responses, and ID collisions.
  • Documents the behavior and temporarily pins an SDK fork for pagination support; a published SDK release is required before merging.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
internal/​tui/​tui_test.go Updates source-count expectations for Trash.
internal/​tui/​trash.go Implements restoration, mutation restrictions, and contextual help.
internal/​tui/​trash_test.go Tests navigation, pagination, restoration, and identity safeguards.
internal/​tui/​move.go Excludes Trash from move destinations.
internal/​tui/​mail.go Integrates Trash navigation, reading, and action guards.
internal/​tui/​mail_test.go Adjusts mail-source expectations for Trash.
internal/​tui/​collections_test.go Accounts for Trash during collection discovery.
internal/​mail/​source.go Adds the Trash source kind.
internal/​mail/​page.go Adapts paginated Trash topics into list rows.
go.sum Records checksums for the temporary SDK fork.
go.mod Pins the SDK fork containing pagination support.
docs/​tui.md Documents Trash controls and restrictions.
docs/​architecture/​mail-sources-and-paging.md Explains Trash identities and restore behavior.

Review effort: Balanced

Comment thread internal/tui/trash.go Outdated
Comment on lines +78 to +84
if v.currentSourceKind() != mail.KindTrash {
return notify("Thread restored")
}
// A page or live head read begun before the restore may still contain this
// topic. Ignore those answers so they cannot resurrect the restored row.
v.moreRequestID++
v.liveRequestID++

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8466640. Confirmed the reported ordering: A pre-restore Trash live refresh could still pass the request/source checks after a round trip through the Imbox: navigation invalidates paginated reads but does not change the live refresh generation.

The fix moves live-refresh invalidation ahead of the non-Trash early return, still after the restore error check. Paging invalidation remains scoped to Trash so a late restore does not interfere with the other source's page read.

The new regression holds an actual SDK refresh response from an offline test server, starts a restore with i, navigates to the Imbox, completes the successful restore, returns to a freshly read Trash list, and then delivers the old response. It reproduced the restored topic reappearing before the fix and now rejects that response. A separate test checks that a failed restore still allows an otherwise valid refresh.

TUI/mail tests, the targeted race check, and lint pass. The full test suite still hits the previously observed TestFindBareLinksPastRejectedPrefixesIsLinear timing failure; the new regressions pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants